package com.worley.argutils.bk.command;

import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.ValueOperations;

import com.worley.argutils.bk.Benchmark;
import com.worley.argutils.bk.RunState;

public class GetCommand extends Benchmark {

    public static final String NAME = "GET";

    private ValueOperations<String, String> ops;
    
    public GetCommand(RedisOperations<String, String> redisOps, RunState rs) {
        super(rs);
        ops = redisOps.opsForValue();
    }

    @Override
    public void run() {
        int loops = rs.getLoops();
        int hc = rs.hashCode();
        do {
            long s = System.nanoTime();
            for (int i = 0; i < RunState.BATCH_UPDATE_COUNT; i++) {
                ops.get(String.format(KEY_FORMAT, loops, i, hc));
            }
            rs.accTotalReq();
            rs.accTotalNanoTime(System.nanoTime() - s);
        } while (--loops > 0);
    }

    @Override
    public String getName() {
        return NAME;
    }

}
